# -*- coding: utf-8 -*-
"""
Created on Tue Sep 28 17:54:38 2021

@author: Administrator
"""
from skimage import data,util
from matplotlib import pyplot as plt
import numpy as np
from scipy import ndimage
img=data.coffee()
noise_img=np.zeros(img.shape)
new_img=np.zeros(img.shape) 
for i in range(3):
    grayimg=data.coffee()[:,:,i]
    noise_img[:,:,i]=util.random_noise(grayimg,mode='s&p',seed=None,clip=True)
    n=3
    new_img[:,:,i]=ndimage.median_filter(noise_img[:,:,i],(n,n))
    plt.figure()
    plt.imshow(img,cmap='gray')
    plt.figure()
    plt.imshow(noise_img,cmap='gray')
    plt.figure()
    plt.imshow(new_img,cmap='gray')
    
    

